#include <iostream>
#include "Dat3.h"

using namespace std;

enum m_type{LONG,SHORT};

class Dat3
{
private:
  int day;
  struct month_Year
  {
    int year;
    int mon;
    m_type mon_type;
    const month_Year operator +=(int m){
      mon+=m;
      while(mon>12){//fix years
	mon-=12;
	year++;
      }
      if(mon == 4 || mon == 6 || mon == 9 || mon ==11 || mon == 2)
	mon_type=SHORT;
      else
	mon_type=LONG;
      return *this;
    }
    const month_Year operator ++(int){
      *this+=1;
      return *this;
    }
  }m;
  
  void  normalize(){//fix days and months
    bool tooManyDays=true;
    while(tooManyDays){
      if(m.mon_type==LONG && this->day>31){
	this->day-=31;
	m++;
      } else if(m.mon_type==SHORT && this->day>30){
	this->day-=30;
	m++;
      } else if(m.year%4==0 && m.mon==2 && this->day>29){
	this->day-=29;
	m++;
      }else if(m.year%4!=0 &&m.mon==2 && this->day>28){
	this->day-=28;
	m++;
      }else
	tooManyDays=false;
    }
  }
public:
  Dat3(int day, int mon, int year){    //constructor
    if(mon == 4 || mon == 6 || mon == 9 || mon ==11 || mon == 2)
      m.mon_type=SHORT;
    else
      m.mon_type=LONG;
    this->day=day;
    m.mon=mon;
    m.year=year;
  }
  
  const Dat3 operator +=(int d){
    day+=d;
    normalize();
    return *this;
  }
  const Dat3 operator ++(int){
    day+=1;
    normalize();
  }
  //getters
  int getDay(){
    return day;
  }
  int getMonth(){
    return m.mon;
  }
  int getYear(){
    return m.year;
  }
};
/*Testing function
int main( ) {
  int day,m,y;
  while(1){
    cout<< "enter day: ";
    cin>>day;
    cout<< "enter mon: ";
    cin>>m;
    y=2004;
    Dat3 d(day,m,y);
    cout<<d.getDay()<<" "<<d.getMonth()<<" "<<d.getYear()<<endl;
    d++;
    cout<<d.getDay()<<" "<<d.getMonth()<<" "<<d.getYear()<<endl;
    d++;
    cout<<d.getDay()<<" "<<d.getMonth()<<" "<<d.getYear()<<endl;
    d++;
    cout<<d.getDay()<<" "<<d.getMonth()<<" "<<d.getYear()<<endl;
  }
  return 0;
}
*/
